-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Razor completion bugs #6441
Fix Razor completion bugs #6441
Conversation
const line = razorDocument.lineAt(hostDocumentPosition.line); | ||
const lineText = line.text.substring(0, hostDocumentPosition.character); | ||
if ( | ||
lineText.endsWith('@') || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this check looks terrible - honestly it makes me cringe too 😅 If anyone has suggestions for an alternative, feel free to suggest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works but... ugh...
What's the benefit of having a using snippet? Can we just make a server fix for Razor to add it's own completion for @
directives? I think we already do have some... (like @co
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I just remembered - I think a long time ago I deleted code that added these
https://github.com/dotnet/razor/pull/6012/files#diff-052d5834149367e2bcf4d95d0740ddb4b346116cfcd64e568d0b5eca38f7b8aeL289
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of having a using snippet? Can we just make a server fix for Razor to add it's own completion for @ directives? I think we already do have some...
I'm guessing a using snippet might be beneficial in the case where the user is already in a C# context and would want to insert something like using () { }
?
I've filed dotnet/razor#9330 to track a (still hacky) server-side fix that we can use in both VS and VS Code. In the interest of getting a temporary fix in I'm planning on merging this version for now, but will follow up soon on the server-side fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only signing off on the roslyn-ide changes (l10n)
lineText.endsWith('@') || | ||
lineText.endsWith( | ||
'@u' || | ||
lineText.endsWith('@us') || | ||
lineText.endsWith('@usi') || | ||
lineText.endsWith('@usin') || | ||
lineText.endsWith('@using') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may have come up with the best way. If the user has already finished typing @using
, does the item still need to be added?
lineText.endsWith('@') || | |
lineText.endsWith( | |
'@u' || | |
lineText.endsWith('@us') || | |
lineText.endsWith('@usi') || | |
lineText.endsWith('@usin') || | |
lineText.endsWith('@using') | |
lineText.endsWith('@') || | |
lineText.endsWith('@u') || | |
lineText.endsWith('@us') || | |
lineText.endsWith('@usi') || | |
lineText.endsWith('@usin') || | |
lineText.endsWith('@using') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving, and feel gross with you.
@allisonchou Sounds like this would be an issue if snippet is disabled? Have you considered adding a specific completion provider in razor instead? That should cover both VS and VSCode |
Yeah, it would be an issue in VS if snippets were disabled.
That's a good idea! I've filed dotnet/razor#9330 and dotnet/razor#9331 as follow ups. I'm going to merge this version for now and then revisit your suggestion soon in the near future in the interest of at least getting some sort of temporary fix in. |
These fixes are both pretty hacky, but I believe we lack reasonable alternatives at the moment.
ushort
appears with the snippet icon instead of the keyword icon):This is because we're deserializing the LSP completion item type returned by Roslyn into a VS Code completion item type. Notice that the
CompletionItemKinds
on both types are off by one:We technically have the same bug in VS, but since we have snippets available there (snippets are currently unavailable for Razor in VS Code), we still get
using
in the completion list (screenshot below is the current experience in VS):However, both VS and VS Code are missing
using
the keyword in the list. The reason we're not getting the keyword is because we're trying to get completions at__o = [||]
, which is not a valid location for a using statement.End result after both of these fixes (1 & 2):